#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018, Niklas Hauser
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":driver:ft245"
    module.description = """\
# FT245 USB FIFO

The FT245R USB FIFO from Future Technology Devices International is a
single chip USB to parallel FIFO bidirectional data transfer interface.

Wr and Rd must be GpioOutputs and set to output mode before.
Rxf and Txe must be GpioInputs.
Port is switched between input and output mode.

## Example

```cpp
#include <modm/architecture.hpp>
#include <modm/driver/usb/ft245.hpp>
using namespace modm::platform;

using myPort = GpioPort<GpioD0, 8>;
using Rxf    = GpioInputC11;
using Txe    = GpioInputC10;
using Rd     = GpioOutputA15;
using Wr     = GpioOutputA9;

using myFt = modm::Ft245<myPort, Rd, Wr, Rxf, Txe>;

int
main()
{
    Rd::setOutput(modm::Gpio::High);
    Wr::setOutput(modm::Gpio::Low);

    while (true)
    {
        uint8_t c;
        if (myFt::read(c)) {
            myFt::write(c + 1);
        }
    }
}
```
"""

def prepare(module, options):
    module.depends(":architecture:gpio")
    return True

def build(env):
    env.outbasepath = "modm/src/modm/driver/usb"
    env.copy("ft245.hpp")
    env.copy("ft245_impl.hpp")
